!function(t){"use strict";let e=wpcWidgets.wpcItemNum;function i(){t(".wpc-sorting-list").sortable({items:"> div.wpc-sorting-item-wrapper",delay:75,placeholder:"wpc-filter-item-shadow",refreshPositions:!0,cursor:"move",handle:".wpc-sorting-item-handle",axis:"y",update:function(t,e){n(e.item.parent(".wpc-sorting-list"))},start:function(e,i){let n=i.item,a=i.item.children(".wpc-sorting-item-top"),p=a.height()+2;a.hasClass("wpc-opened")&&(a.removeClass("wpc-opened"),n.css("max-height",p+"px"),t(this).sortable("refreshPositions"))},stop:function(t,e){e.item.css("max-height","none")}})}function n(i){let n=i.find(".wpc-sorting-item-label"),a="",p="",r=RegExp("^"+e+"[\\d]{1,100}$");n.length>0&&n.each(function(i,n){p=(a=t(n).val()).replace(r,e+(i+1)),t(n).val(p).trigger("change")})}t(document).ready(function(){t(document).on("click",".wpc-sorting-item-title",function(){t(this).parent(".wpc-sorting-item-top").toggleClass("wpc-opened")}),t(document).on("click",".wpc-sorting-item-remove",function(){let e=t(this),i=e.parents("div.wpc-sorting-list");if(i.find(".wpc-sorting-item-wrapper").length<2)return;let a=e.parents("div.widget"),p=a.children(".widget-inside"),r=p.find(".widget-control-save"),s=p.find(".widget-id").val();e.parents(".wpc-sorting-item-wrapper").remove(),n(i),window.wpWidgets.dirtyWidgets[s]=!0,a.addClass("widget-dirty"),r.prop("disabled",!1).val(wp.i18n.__("Save"))}),t(document).on("change",".wpc-orderby-select",function(e){let i=t(this),n=i.parents(".wpc-sorting-item-inside").find(".wpc-sorting-item-meta-key-wrapper");return"m"===i.val()||"n"===i.val()?n.addClass("wpc-opened"):n.removeClass("wpc-opened"),!0}),t(document).on("input change",".wpc-sorting-item-label",function(){let e=t(this),i=e.parents(".wpc-sorting-item-wrapper");i.parents(".wpc-sorting-list");let n=i.find(".wpc-sorting-item-title");if(""===e.val()){let a=i.index();n.text(n.data("title")+(a+1))}else(function t(e,i){i.text(e.val())})(e,n)}),t(document).on("widget-added widget-updated",function(){i(),t(".wpc-help-tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200,keepAlive:!0,maxWidth:"220px"})}),t(document).on("focus",".wpc-sorting-item-label",function(){let i=t(this).val(),n=RegExp("^"+e+"[\\d]{1,100}$"),a=i.replace(n,"");t(this).val(a)}),t(document).on("click",".wpc-add-sorting-item",function(e){e.preventDefault();let i=t(this).parents(".wpc-add-sorting-item-wrapper").parent(),n=i.find(".wpc-sorting-list"),a=t(i.find(".wpc-new-sorting-item").html()),p=a.find(".wpc-sorting-item-title"),r="wpc_new_id",s=n.find(".wpc-sorting-item-wrapper").length+1,o=function(t,e){return e.replace(r,s)};a.find('[id*="'+r+'"]').attr("id",o),a.find('[for*="'+r+'"]').attr("for",o),a.find('[name*="'+r+'"]').attr("name",o),a.find('[value*="'+r+'"]').attr("value",o),p.text(p.data("title")+s),a.attr("class",o),a.find(".wpc-sorting-item-top").addClass("wpc-opened"),t("input.wpc-ballast").trigger("change"),n.append(a)}),"undefined"!=typeof elementor&&elementor.hooks.addAction("panel/widgets/wp-widget-wpc_sorting_widget/controls/wp_widget/loaded",function(e){setTimeout(function(){i(),t("input.wpc-ballast").trigger("change")},500)}),i()})}(jQuery);